package com.chengqj;

import com.chengqj.dao.UserDO;
import com.chengqj.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Copyright © 2020年 com.qxkj. All rights reserved.
 *
 * @author chengqj
 * 接口中A、B两个方法，A无@Transactional标签，B有，上层通过A间接调用B，此时事务不生效。
 * version 1.0.0 (接口必须带上)
 * @date 2020/11/5 16:43
 */
@Service
public class UserServiceTowMethod {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private UserServiceTowService userServiceTowService;

    /**
     * 接口中A、B两个方法，A无@Transactional标签，B有，上层通过A间接调用B，此时事务不生效。
     *
     * @param userDO
     * @return
     */
    public UserDO createTwoService(UserDO userDO) {
//        insert(userDO);
        userServiceTowService.insert(userDO);
        return userDO;
    }

    /**
     * 添加一条记录
     *
     * @param userDO
     * @return
     */
    @Transactional
    public UserDO insert(UserDO userDO) {
        userRepository.save(userDO);
        throw new RuntimeException();
    }


}
